﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace PressMenu2
{
    public class MySprite
    {
        private Texture2D tData;
        int nFrame;
        int iWidth;
        int iHeight;
        int iDong, iCot;
        int curFrame;
        bool flagAutoFinish = false;

        public MySprite(Texture2D tData, int iWidth, int iHeight)
        {
            this.iDong = (int)(tData.Width / iWidth);
            this.iCot = (int)(tData.Height / iHeight);
            this.nFrame = iDong*iCot;
            this.iHeight = iHeight;
            this.iWidth = iWidth;
            this.tData = tData;
        }

        public void NextFrame()
        {
            if (curFrame < nFrame - 1)
            {
                curFrame++;
                flagAutoFinish = false;
            }
            else
            {
                curFrame = 0;
                flagAutoFinish = true;
            }
        }

        public void PrevFrame()
        {
            curFrame = curFrame == 0 ? nFrame-1 : curFrame-1;
        }

        

        public void Render(SpriteBatch sb)
        {
            int i = curFrame / iDong;
            int j = curFrame % iDong;
            sb.Draw(tData, new Rectangle(0, 0, iWidth, iHeight), new Rectangle(j * iWidth, i * iHeight, iWidth, iHeight), Color.White);
        }

        public void Render(SpriteBatch sb, float x, float y)
        {
            int i = curFrame / iDong;
            int j = curFrame % iDong;
            sb.Draw(tData, new Vector2(x-cDef.dx,y-cDef.dy), new Rectangle(j * iWidth, i * iHeight, iWidth, iHeight), Color.White);
        }

        public int Width
        {
            get{ return this.tData.Width/this.nFrame; }
        }

        public int Height
        {
            get{ return this.tData.Height; }
        }


        public bool FlagAutoFinish
        {
            get { return flagAutoFinish; }
        }

        ~MySprite()
        {

        }
    }
}
